package com.authine.cloudpivot.web.api.quartz.task;

import com.authine.cloudpivot.engine.api.model.runtime.BizObjectModel;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectQueryModel;
import com.authine.cloudpivot.engine.component.query.api.FilterExpression;
import com.authine.cloudpivot.engine.component.query.api.Page;
import com.authine.cloudpivot.engine.component.query.api.helper.PageableImpl;
import com.authine.cloudpivot.engine.component.query.api.helper.Q;
import com.authine.cloudpivot.engine.enums.type.QueryDisplayType;
import com.authine.cloudpivot.web.api.dubbo.DubboConfigService;
import com.authine.cloudpivot.web.api.quartz.QuartzManger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
public class JobManger implements CommandLineRunner {
    @Autowired
    private DubboConfigService dubboConfigService; // 注入Engine服务

    @Autowired
    private  QuartzManger quartzManger;

    @Override
    public void run(String... args) throws Exception {
        init();
    }

    public void modify(){
        //根据id获取招聘需求提报的相关信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("xtpz");
        queryModel.setQueryCode("xtpz");
        queryModel.setPageable(pageable);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("zbtips","zbsjDay1","zbsjHour1","zbsjDay2","zbsjHour2","zbsjDay3","zbsjHour3",
                "zxzbtips","zxzbsjDay1","zxzbsjHour1","zxzbsjDay2","zxzbsjHour2","zxzbsjDay3","zxzbsjHour3","zxzbsjDay4","zxzbsjHour4",
                "zpzbtips","zpzbsjDay1","zpzbsjHour1","zpzbsjDay2","zpzbsjHour2","zpzbsjDay3","zpzbsjHour3","zpzbsjDay4","zpzbsjHour4",
                "whttips","whtsjDay1","whtsjHour1","whtsjDay2","whtsjHour2","whtsjDay3","whtsjHour3",
                "zpzztips","zpzzsjDay1","zpzzsjHour1","xmyqtips","xmyqDay"));
        queryModel.setOptions(option);
        Page<BizObjectModel> recruitmentDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);

        //更新招聘需求提报时间
        BizObjectModel model = recruitmentDatas.getContent().get(0);
        String zbtips = model.get("zbtips").toString();
        if("是".equals(zbtips)){
            String zbsjDay1 = model.get("zbsjDay1").toString();
            String zbsjHour1 = model.get("zbsjHour1").toString();
            String zbsjCron1 = "0 0 " + zbsjHour1 +" ? * "+ getWeekDay(zbsjDay1);
            System.out.println("未提交周报第一次提醒："+zbsjCron1);
            // 未提交周报提醒
            quartzManger.modifyJobTime("remindUncommittedReport1", "demand", "remindUncommittedReport1Trigger", "demandTriggerGroup",
                    zbsjCron1);
            //quartzManger.addJob("remindUncommittedReport1", "demand", "remindUncommittedReport1Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
            //        "* 0/1 * * * ?");

            String zbsjDay2 = model.get("zbsjDay2").toString();
            String zbsjHour2 = model.get("zbsjHour2").toString();
            String zbsjCron2 = "0 0 " + zbsjHour2 +" ? * "+ getWeekDay(zbsjDay2);
            System.out.println("未提交周报第二次提醒："+zbsjCron2);
            // 未提交周报提醒
            quartzManger.modifyJobTime("remindUncommittedReport2", "demand", "remindUncommittedReport2Trigger", "demandTriggerGroup",
                    zbsjCron2);
            //quartzManger.addJob("remindUncommittedReport2", "demand", "remindUncommittedReport2Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
            //        "* 0/1 * * * ?");
        }else{
            System.out.println("关闭未提交周报第一次提醒：");
            // 未提交周报提醒
            quartzManger.removeJob("remindUncommittedReport1", "demand", "remindUncommittedReport1Trigger", "demandTriggerGroup");
            System.out.println("关闭未提交周报第二次提醒：");
            // 未提交周报提醒
            quartzManger.removeJob("remindUncommittedReport2", "demand", "remindUncommittedReport2Trigger", "demandTriggerGroup");
        }

        String zbsjDay3 = model.get("zbsjDay3").toString();
        String zbsjCron3 = "59 59 23 ? * "+ getWeekDay(zbsjDay3);
        System.out.println("周报自动提交："+zbsjCron3);
        quartzManger.modifyJobTime("commitReport", "demand", "commitReportTrigger", "demandTriggerGroup",
                zbsjCron3);
        //quartzManger.addJob("commitReport", "demand", "commitReportTrigger", "demandTriggerGroup", CommitReportJob.class,
        //        "* 0/1 * * * ?");

        //执行月报
        String zxzbtips = model.get("zxzbtips").toString();
        if("是".equals(zxzbtips)){
            String zxzbsjDay1 = model.get("zxzbsjDay1").toString();
            String zxzbsjHour1 = model.get("zxzbsjHour1").toString();
            String zxzbsjCron1 = "0 0 " + zxzbsjHour1 +" "+zxzbsjDay1+" * ?";
            System.out.println("执行周报补交提醒："+ zxzbsjCron1);
            // 执行周报补交提醒
            quartzManger.modifyJobTime("zxRemindUnArchivedReport", "demand", "zxRemindUnArchivedReportTrigger", "demandTriggerGroup",
                    zxzbsjCron1);
            //quartzManger.addJob("zxRemindUnArchivedReport", "demand", "zxRemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
            //        "* 0/1 * * * ?","zx");

            String zxzbsjDay3 = model.get("zxzbsjDay3").toString();
            String zxzbsjHour3 = model.get("zxzbsjHour3").toString();
            String zxzbsjCron3 = "0 0 " + zxzbsjHour3 +" "+zxzbsjDay3+" * ?";
            System.out.println("执行周报复核提醒："+ zxzbsjCron3);
            // 执行周报复核提醒
            quartzManger.modifyJobTime("zxRemindUnReviewedReport", "demand", "zxRemindUnReviewedReportTrigger", "demandTriggerGroup",
                    zxzbsjCron3);
            //quartzManger.addJob("zxRemindUnReviewedReport", "demand", "zxRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
            //        "* 0/1 * * * ?","zx");
        }else{
            System.out.println("关闭执行周报补交提醒：");
            quartzManger.removeJob("zxRemindUnArchivedReport", "demand", "zxRemindUnArchivedReportTrigger", "demandTriggerGroup");
            System.out.println("关闭执行周报复核提醒：");
            quartzManger.removeJob("zxRemindUnReviewedReport", "demand", "zxRemindUnReviewedReportTrigger", "demandTriggerGroup");
        }

        String zxzbsjDay2 = model.get("zxzbsjDay2").toString();
        String zxzbsjCron2 = "59 59 23 "+zxzbsjDay2 +" * ?";
        System.out.println("执行周报复核:"+zxzbsjCron2);
        // 执行周报自动复核
        quartzManger.modifyJobTime("zxReviewReport", "demand", "zxReviewReportTrigger", "demandTriggerGroup",
                zxzbsjCron2);
        //quartzManger.addJob("zxReviewReport", "demand", "zxReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
        //        "* 0/1 * * * ?","zx");


        String zxzbsjDay4 = model.get("zxzbsjDay4").toString();
        String zxzbsjCron4 = "59 59 23 "+ zxzbsjDay4 +" * ?";
        System.out.println("执行周报归档："+zxzbsjCron4);
        // 执行周报自动归档
        quartzManger.modifyJobTime("zxArchiveReport", "demand", "zxArchiveReportTrigger", "demandTriggerGroup",
                zxzbsjCron4);
        //quartzManger.addJob("zxArchiveReport", "demand", "zxArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
        //        "* 0/1 * * * ?","zx");

        //招聘月报
        String zpzbtips = model.get("zpzbtips").toString();
        if("是".equals(zpzbtips)){
            String zpzbsjDay1 = model.get("zpzbsjDay1").toString();
            String zpzbsjHour1 = model.get("zpzbsjHour1").toString();
            String zpzbsjCron1 = "0 0 " + zpzbsjHour1 +" "+zpzbsjDay1+" * ?";
            System.out.println("未补交周报提醒："+ zpzbsjCron1);
            // 招聘周报补齐提醒
            quartzManger.modifyJobTime("remindUnArchivedReport", "demand", "RemindUnArchivedReportTrigger", "demandTriggerGroup",
                    zpzbsjCron1);
            //quartzManger.addJob("remindUnArchivedReport", "demand", "RemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
            //        "* 0/1 * * * ?","zp");

            String zpzbsjDay3 = model.get("zpzbsjDay3").toString();
            String zpzbsjHour3 = model.get("zpzbsjHour3").toString();
            String zpzbsjCron3 = "0 0 " + zpzbsjHour3 +" "+zpzbsjDay3+" * ?";
            System.out.println("招聘周报复核提醒："+ zpzbsjCron3);
            // 执行周报复核提醒
            quartzManger.modifyJobTime("zpRemindUnReviewedReport", "demand", "zpRemindUnReviewedReportTrigger", "demandTriggerGroup",
                    zpzbsjCron3);
            //quartzManger.addJob("zpRemindUnReviewedReport", "demand", "zpRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
            //        "* 0/1 * * * ?","zp");
        }else{
            System.out.println("关闭未补交周报提醒：");
            quartzManger.removeJob("remindUnArchivedReport", "demand", "RemindUnArchivedReportTrigger", "demandTriggerGroup");

            System.out.println("关闭招聘周报复核提醒：");
            // 执行周报复核提醒
            quartzManger.removeJob("zpRemindUnReviewedReport", "demand", "zpRemindUnReviewedReportTrigger", "demandTriggerGroup");

        }

        String zpzbsjDay2 = model.get("zpzbsjDay2").toString();
        String zpzbsjCron2 = "59 59 23 "+zpzbsjDay2 +" *  ?";
        System.out.println("执行周报复核:"+zpzbsjCron2);
        // 执行周报自动复核
        quartzManger.modifyJobTime("zpReviewReport", "demand", "zpReviewReportTrigger", "demandTriggerGroup",
                zpzbsjCron2);
        //quartzManger.addJob("zpReviewReport", "demand", "zpReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
        //        "* 0/1 * * * ?","zp");

        String zpzbsjDay4 = model.get("zpzbsjDay4").toString();
        String zpzbsjCron4 = "59 59 23 "+ zpzbsjDay4 +" *  ?";
        System.out.println("执行周报归档："+ zpzbsjCron4);
        // 执行周报自动归档
        quartzManger.modifyJobTime("zpArchiveReport", "demand", "zpArchiveReportTrigger", "demandTriggerGroup",
                zpzbsjCron4);
        //quartzManger.addJob("zpArchiveReport", "demand", "zpArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
        //        "* 0/1 * * * ?","zp");

        //无合同立项配置
        String whttips = model.get("whttips").toString();
        if("是".equals(whttips)){
            int whtsjDay1 = Integer.parseInt(model.get("whtsjDay1").toString());
            String whtsjHour1 = model.get("whtsjHour1").toString();

            int whtsjDay2 = Integer.parseInt(model.get("whtsjDay2").toString());
            String whtsjHour2 = model.get("whtsjHour2").toString();

            int whtsjDay3 = Integer.parseInt(model.get("whtsjDay3").toString());
            String whtsjHour3 = model.get("whtsjHour3").toString();

            String  whtsjCron1 = "0 0 "  + whtsjHour1 +" ? * MON";
            System.out.println("无合同提醒:"+whtsjCron1);
            quartzManger.modifyJobTime("remindNoContract1", "demand", "remindNoContract1Trigger", "demandTriggerGroup",
                    whtsjCron1);
            //quartzManger.addJob("remindNoContract1", "demand", "remindNoContract1Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //        "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,1);

            String  whtsjCron2 = "0 0 "  + whtsjHour2 +" ? * MON";
            System.out.println("无合同预警:"+whtsjCron2);
            quartzManger.modifyJobTime("remindNoContract2", "demand", "remindNoContract2Trigger", "demandTriggerGroup",
                    whtsjCron2);
            //quartzManger.addJob("remindNoContract2", "demand", "remindNoContract2Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //       "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,2);

            String  whtsjCron3 = "0 0 "  + whtsjHour3 +" ? * MON";
            System.out.println("无合同预警:"+whtsjCron3);
            quartzManger.modifyJobTime("remindNoContract3", "demand", "remindNoContract3Trigger", "demandTriggerGroup",
                    whtsjCron3);
            //quartzManger.addJob("remindNoContract3", "demand", "remindNoContract3Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //        "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,3);
        }else{
            System.out.println("关闭无合同提醒:");
            quartzManger.removeJob("remindNoContract1", "demand", "remindNoContract1Trigger", "demandTriggerGroup");

            System.out.println("关闭无合同预警:");
            quartzManger.removeJob("remindNoContract2", "demand", "remindNoContract2Trigger", "demandTriggerGroup");

            System.out.println("关闭无合同预警:");
            quartzManger.removeJob("remindNoContract3", "demand", "remindNoContract3Trigger", "demandTriggerGroup");
        }

        //招聘追踪
        String zpzztips = model.get("zpzztips").toString();
        if("是".equals(zpzztips)){
            int zpzzsjDay1 = Integer.parseInt(model.get("zpzzsjDay1").toString());
            String zpzzsjHour1 = model.get("zpzzsjHour1").toString();
            String  zpzzsjCron1 = "0 0 "  + zpzzsjHour1 +" * *  ?";
            System.out.println("招聘追踪:"+zpzzsjCron1);
            quartzManger.modifyJobTime("recruitmentTrace", "demand", "recruitmentTraceTrigger", "demandTriggerGroup",
                    zpzzsjCron1);
            //quartzManger.addJob("recruitmentTrace", "demand", "recruitmentTraceTrigger", "demandTriggerGroup", RecruitmentTraceJob.class,
            //        "* 0/1 * * * ?",zpzzsjDay1);
        }else{
            System.out.println("关闭招聘追踪:");
            quartzManger.removeJob("recruitmentTrace", "demand", "recruitmentTraceTrigger", "demandTriggerGroup");
        }

        //需求自动关闭
        //quartzManger.addJob("closeDemand", "demand", "closeDemandTrigger", "demandTriggerGroup", CloseDemandJob.class,
        //        "0 0 0 ? * *");

        quartzManger.startJobs();

    }

    public void init(){
        //根据id获取招聘需求提报的相关信息
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("xtpz");
        queryModel.setQueryCode("xtpz");
        queryModel.setPageable(pageable);
        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
        option.setQueryDisplayType(QueryDisplayType.APPEND);
        option.setCustomDisplayColumns(Arrays.asList("zbtips","zbsjDay1","zbsjHour1","zbsjDay2","zbsjHour2","zbsjDay3","zbsjHour3",
                "zxzbtips","zxzbsjDay1","zxzbsjHour1","zxzbsjDay2","zxzbsjHour2","zxzbsjDay3","zxzbsjHour3","zxzbsjDay4","zxzbsjHour4",
                "zpzbtips","zpzbsjDay1","zpzbsjHour1","zpzbsjDay2","zpzbsjHour2","zpzbsjDay3","zpzbsjHour3","zpzbsjDay4","zpzbsjHour4",
                "whttips","whtsjDay1","whtsjHour1","whtsjDay2","whtsjHour2","whtsjDay3","whtsjHour3",
                "zpzztips","zpzzsjDay1","zpzzsjHour1","xmyqtips","xmyqDay"));
        queryModel.setOptions(option);
        Page<BizObjectModel> recruitmentDatas = dubboConfigService.getBizObjectFacade().queryBizObjects(queryModel);

        //更新招聘需求提报时间
        BizObjectModel model = recruitmentDatas.getContent().get(0);
        String zbtips = model.get("zbtips").toString();
        if("是".equals(zbtips)){
            String zbsjDay1 = model.get("zbsjDay1").toString();
            String zbsjHour1 = model.get("zbsjHour1").toString();
            String zbsjCron1 = "0 0 " + zbsjHour1 +" ? * "+ getWeekDay(zbsjDay1);
            System.out.println("未提交周报第一次提醒："+zbsjCron1);
            // 未提交周报提醒
            quartzManger.addJob("remindUncommittedReport1", "demand", "remindUncommittedReport1Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
                    zbsjCron1);
            //quartzManger.addJob("remindUncommittedReport1", "demand", "remindUncommittedReport1Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
            //        "* 0/1 * * * ?");

            String zbsjDay2 = model.get("zbsjDay2").toString();
            String zbsjHour2 = model.get("zbsjHour2").toString();
            String zbsjCron2 = "0 0 " + zbsjHour2 +" ? * "+ getWeekDay(zbsjDay2);
            System.out.println("未提交周报第二次提醒："+zbsjCron2);
            // 未提交周报提醒
            quartzManger.addJob("remindUncommittedReport2", "demand", "remindUncommittedReport2Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
                    zbsjCron2);
            //quartzManger.addJob("remindUncommittedReport2", "demand", "remindUncommittedReport2Trigger", "demandTriggerGroup", RemindUncommittedReportJob.class,
            //        "* 0/1 * * * ?");
        }

        String zbsjDay3 = model.get("zbsjDay3").toString();
        String zbsjCron3 = "59 59 23 ? * "+ getWeekDay(zbsjDay3);
        System.out.println("周报自动提交："+zbsjCron3);
        quartzManger.addJob("commitReport", "demand", "commitReportTrigger", "demandTriggerGroup", CommitReportJob.class,
                zbsjCron3);
        //quartzManger.addJob("commitReport", "demand", "commitReportTrigger", "demandTriggerGroup", CommitReportJob.class,
        //        "* 0/1 * * * ?");

        //执行月报
        String zxzbtips = model.get("zxzbtips").toString();
        if("是".equals(zxzbtips)){
            String zxzbsjDay1 = model.get("zxzbsjDay1").toString();
            String zxzbsjHour1 = model.get("zxzbsjHour1").toString();
            String zxzbsjCron1 = "0 0 " + zxzbsjHour1 +" "+zxzbsjDay1+" * ?";
            System.out.println("执行周报补交提醒："+ zxzbsjCron1);
            // 执行周报补交提醒
            quartzManger.addJob("zxRemindUnArchivedReport", "demand", "zxRemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
                    zxzbsjCron1,"zx");
            //quartzManger.addJob("zxRemindUnArchivedReport", "demand", "zxRemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
            //        "* 0/1 * * * ?","zx");

            String zxzbsjDay3 = model.get("zxzbsjDay3").toString();
            String zxzbsjHour3 = model.get("zxzbsjHour3").toString();
            String zxzbsjCron3 = "0 0 " + zxzbsjHour3 +" "+zxzbsjDay3+" * ?";
            System.out.println("执行周报复核提醒："+ zxzbsjCron3);
            // 执行周报复核提醒
            quartzManger.addJob("zxRemindUnReviewedReport", "demand", "zxRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
                    zxzbsjCron3,"zx");
            //quartzManger.addJob("zxRemindUnReviewedReport", "demand", "zxRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
            //        "* 0/1 * * * ?","zx");
        }

        String zxzbsjDay2 = model.get("zxzbsjDay2").toString();
        String zxzbsjCron2 = "59 59 23 "+zxzbsjDay2 +" * ?";
        System.out.println("执行周报复核:"+zxzbsjCron2);
        // 执行周报自动复核
        quartzManger.addJob("zxReviewReport", "demand", "zxReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
                zxzbsjCron2,"zx");
        //quartzManger.addJob("zxReviewReport", "demand", "zxReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
        //        "* 0/1 * * * ?","zx");


        String zxzbsjDay4 = model.get("zxzbsjDay4").toString();
        String zxzbsjCron4 = "59 59 23 "+ zxzbsjDay4 +" * ?";
        System.out.println("执行周报归档："+zxzbsjCron4);
        // 执行周报自动归档
        quartzManger.addJob("zxArchiveReport", "demand", "zxArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
                zxzbsjCron4,"zx");
        //quartzManger.addJob("zxArchiveReport", "demand", "zxArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
        //        "* 0/1 * * * ?","zx");

        //招聘月报
        String zpzbtips = model.get("zpzbtips").toString();
        if("是".equals(zpzbtips)){
            String zpzbsjDay1 = model.get("zpzbsjDay1").toString();
            String zpzbsjHour1 = model.get("zpzbsjHour1").toString();
            String zpzbsjCron1 = "0 0 " + zpzbsjHour1 +" "+zpzbsjDay1+" * ?";
            System.out.println("未补交周报提醒："+ zpzbsjCron1);
            // 招聘周报补齐提醒
            quartzManger.addJob("remindUnArchivedReport", "demand", "RemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
                    zpzbsjCron1,"zp");
            //quartzManger.addJob("remindUnArchivedReport", "demand", "RemindUnArchivedReportTrigger", "demandTriggerGroup", RemindUnArchivedReportJob.class,
            //        "* 0/1 * * * ?","zp");

            String zpzbsjDay3 = model.get("zpzbsjDay3").toString();
            String zpzbsjHour3 = model.get("zpzbsjHour3").toString();
            String zpzbsjCron3 = "0 0 " + zpzbsjHour3 +" "+zpzbsjDay3+" * ?";
            System.out.println("招聘周报复核提醒："+ zpzbsjCron3);
            // 执行周报复核提醒
            quartzManger.addJob("zpRemindUnReviewedReport", "demand", "zpRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
                    zpzbsjCron3,"zp");
            //quartzManger.addJob("zpRemindUnReviewedReport", "demand", "zpRemindUnReviewedReportTrigger", "demandTriggerGroup", RemindUnReviewedReportJob.class,
            //        "* 0/1 * * * ?","zp");
        }

        String zpzbsjDay2 = model.get("zpzbsjDay2").toString();
        String zpzbsjCron2 = "59 59 23 "+zpzbsjDay2 +" *  ?";
        System.out.println("执行周报复核:"+zpzbsjCron2);
        // 执行周报自动复核
        quartzManger.addJob("zpReviewReport", "demand", "zpReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
                zpzbsjCron2,"zp");
        //quartzManger.addJob("zpReviewReport", "demand", "zpReviewReportTrigger", "demandTriggerGroup", ReviewReportJob.class,
        //        "* 0/1 * * * ?","zp");

        String zpzbsjDay4 = model.get("zpzbsjDay4").toString();
        String zpzbsjCron4 = "59 59 23 "+ zpzbsjDay4 +" *  ?";
        System.out.println("执行周报归档："+ zpzbsjCron4);
        // 执行周报自动归档
        quartzManger.addJob("zpArchiveReport", "demand", "zpArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
                zpzbsjCron4,"zp");
        //quartzManger.addJob("zpArchiveReport", "demand", "zpArchiveReportTrigger", "demandTriggerGroup", ArchiveReportJob.class,
        //        "* 0/1 * * * ?","zp");

        //无合同立项配置
        String whttips = model.get("whttips").toString();
        if("是".equals(whttips)){
            int whtsjDay1 = Integer.parseInt(model.get("whtsjDay1").toString());
            String whtsjHour1 = model.get("whtsjHour1").toString();

            int whtsjDay2 = Integer.parseInt(model.get("whtsjDay2").toString());
            String whtsjHour2 = model.get("whtsjHour2").toString();

            int whtsjDay3 = Integer.parseInt(model.get("whtsjDay3").toString());
            String whtsjHour3 = model.get("whtsjHour3").toString();

            String  whtsjCron1 = "0 0 "  + whtsjHour1 +" ? * MON";
            System.out.println("无合同提醒:"+whtsjCron1);
            quartzManger.addJob("remindNoContract1", "demand", "remindNoContract1Trigger", "demandTriggerGroup", RemindNoContractJob.class,
                    whtsjCron1,whtsjDay1,whtsjDay2,whtsjDay3,1);
            //quartzManger.addJob("remindNoContract1", "demand", "remindNoContract1Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //        "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,1);

            String  whtsjCron2 = "0 0 "  + whtsjHour2 +" ? * MON";
            System.out.println("无合同预警:"+whtsjCron2);
            quartzManger.addJob("remindNoContract2", "demand", "remindNoContract2Trigger", "demandTriggerGroup", RemindNoContractJob.class,
                    whtsjCron2,whtsjDay1,whtsjDay2,whtsjDay3,2);
            //quartzManger.addJob("remindNoContract2", "demand", "remindNoContract2Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //       "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,2);

            String  whtsjCron3 = "0 0 "  + whtsjHour3 +" ? * MON";
            System.out.println("无合同预警:"+whtsjCron3);
            quartzManger.addJob("remindNoContract3", "demand", "remindNoContract3Trigger", "demandTriggerGroup", RemindNoContractJob.class,
                    whtsjCron3,whtsjDay1,whtsjDay2,whtsjDay3,3);
            //quartzManger.addJob("remindNoContract3", "demand", "remindNoContract3Trigger", "demandTriggerGroup", RemindNoContractJob.class,
            //        "* 0/1 * * * ?",whtsjDay1,whtsjDay2,whtsjDay3,3);
        }

        //招聘追踪
        String zpzztips = model.get("zpzztips").toString();
        if("是".equals(zpzztips)){
            int zpzzsjDay1 = Integer.parseInt(model.get("zpzzsjDay1").toString());
            String zpzzsjHour1 = model.get("zpzzsjHour1").toString();
            String  zpzzsjCron1 = "0 0 "  + zpzzsjHour1 +" * *  ?";
            System.out.println("招聘追踪:"+zpzzsjCron1);
            quartzManger.addJob("recruitmentTrace", "demand", "recruitmentTraceTrigger", "demandTriggerGroup", RecruitmentTraceJob.class,
                    zpzzsjCron1,zpzzsjDay1);
            //quartzManger.addJob("recruitmentTrace", "demand", "recruitmentTraceTrigger", "demandTriggerGroup", RecruitmentTraceJob.class,
            //        "* 0/1 * * * ?",zpzzsjDay1);
        }

        //自动生成周报
        //quartzManger.addJob("createReport", "demand", "createReportTrigger", "demandTriggerGroup", CreateReportJob.class,
        //        " 0 30 23 ? * SUN");

        quartzManger.addJob("createReport", "demand", "createReportTrigger", "demandTriggerGroup", CreateReportJob.class,
                " 0 30 23 ? * SUN");

        //需求自动关闭
        quartzManger.addJob("closeDemand", "demand", "closeDemandTrigger", "demandTriggerGroup", CloseDemandJob.class,
                "0 0 0 ? * *");

        quartzManger.startJobs();

    }



    public void shutdownJobs() {
        modify();
    }

    private String getWeekDay(String weekDay){
        switch (weekDay){
            case "周一":
                return "MON";
            case "周二":
                return "TUE";
            case "周三":
                return "WED";
            case "周四":
                return "THU";
            case "周五":
                return "FRI";
            case "周六":
                return "SAT";
            case "周日":
                return "SUN";
        }
        return null;
    }
}
